package com.ctcd.security.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;


//设置登录的用户名和密码的第二种方式
//@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        //密码加密
        BCryptPasswordEncoder  passwordEncoder = new BCryptPasswordEncoder();
        String password = passwordEncoder.encode("123");
        //roles设置角色
        auth.inMemoryAuthentication().withUser("jack").password(password).roles("admin");
    }



//    一定要有PasswordEncoder
    @Bean
    PasswordEncoder password(){
        return new BCryptPasswordEncoder();
    }
}
